IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SrvrInstncDatabaseMSSQL]') AND type in (N'U'))
BEGIN
     DROP TABLE [dbo].[SrvrInstncDatabaseMSSQL]
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[SrvrInstncDatabaseMSSQL](
     [SrvrInstncDatabaseId]     [int]          NOT NULL,
     [PackageExecutionId]       [bigint]       NOT NULL,
     [StartDt]                  [datetime]     NOT NULL,
     [EndDt]                    [datetime]     NOT NULL,
     [CurrentRecordFlag]        [tinyint]      NOT NULL CONSTRAINT [DF_SrvrInstncDatabaseMSSQL_CurrentRecordFlag] DEFAULT ((0)),
     [DatabaseDeletedFlag]      [tinyint]      NOT NULL CONSTRAINT [DF_SrvrInstncDatabaseMSSQL_DatabaseDeletedFlag]  DEFAULT ((0)),
     [DatabaseId]               [int]              NULL,
     [DatabaseOwnerName]        [varchar](128)     NULL,
     [DateCreated]              [datetime]         NULL,
     [DatabaseReadOnlyFlag]     [tinyint]          NULL,
     [CompatibilityLevel]       [varchar](10)      NULL,
     [Collation]                [varchar](128)     NULL,
     [DBStatus]                 [varchar](30)      NULL,
     [RecoveryModel]            [varchar](15)      NULL,
     [AccessLevel]              [varchar](30)      NULL,
     [AutoCloseFlag]            [tinyint]          NULL,
     [AutoCreateStatsFlag]      [tinyint]          NULL,
     [AutoShrinkFlag]           [tinyint]          NULL,
     [AutoUpdateStatsFlag]      [tinyint]          NULL,
     [AutoUpdateStatsAsyncFlag] [tinyint]          NULL,
     [RecursiveTriggersFlag]    [tinyint]          NULL,
     [TrustworthyFlag]          [tinyint]          NULL,
     [BrokerEnabledFlag]        [tinyint]          NULL,
     [EncryptionFlag]           [tinyint]          NULL,
     CONSTRAINT [PK_SrvrInstncDatabaseMSSQL] PRIMARY KEY CLUSTERED ( [SrvrInstncDatabaseId] ASC, [StartDt] ASC )
) ON [PRIMARY]
GO

SET ANSI_PADDING OFF
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Unique Identifier of a particular Database on a Database Server Instance.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'SrvrInstncDatabaseId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Execution Id of the package that populated or updated this row (usually by SSIS).' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'PackageExecutionId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Effective start date of this record.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'StartDt'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Effective end date of this record.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'EndDt'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating that this record is the current record.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'CurrentRecordFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database has been deleted,' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'DatabaseDeletedFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Database Id from the server.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'DatabaseId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Owner name of the database.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'DatabaseOwnerName'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date/time the database created.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'DateCreated'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for read-only.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'DatabaseReadOnlyFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Compatibility level of the database.  Currently: 80, 90, 100' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'CompatibilityLevel'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Collation of the database.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'Collation'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Status of the database.  Usually: ONLINE, OFFLINE, RESTORING, RECOVERING, SUSPECT, EMERGENCY' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'DBStatus'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Recover model of the database.  Usually: FULL, BULK_LOGGED, SIMPLE' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'RecoveryModel'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Access level of the database.  Usually: SINGLE_USER, RESTRICTED_USER, MULTI_USER' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'AccessLevel'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for Auto Close.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'AutoCloseFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for Auto Create Statistics.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'AutoCreateStatsFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for Auto Shrink.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'AutoShrinkFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for Auto Update Statistics.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'AutoUpdateStatsFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for Auto Update Statistics Asynchronously.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'AutoUpdateStatsAsyncFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set for Recursive Triggers.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'RecursiveTriggersFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is set as Trustworthy.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'TrustworthyFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database is enabled for service broken.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'BrokerEnabledFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Flag indicating whether this database has encryption enabled.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL', @level2type=N'COLUMN',@level2name=N'EncryptionFlag'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Server instnace databases.  Contains effective dated list of all databases and database history for a server instance.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SrvrInstncDatabaseMSSQL'
GO
